home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / sortar1a / frmmain.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-09-29  |  13.7 KB  |  379 lines

  1. VERSION 5.00
  2. Begin VB.Form frmMain 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Sort Array"
  5.    ClientHeight    =   2310
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   2925
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    ScaleHeight     =   2310
  12.    ScaleWidth      =   2925
  13.    StartUpPosition =   3  'Windows Default
  14.    Begin VB.CommandButton cmdSort 
  15.       Caption         =   "Sort Array"
  16.       Height          =   375
  17.       Left            =   840
  18.       TabIndex        =   13
  19.       Top             =   1920
  20.       Width           =   1215
  21.    End
  22.    Begin VB.Frame frmeSep 
  23.       Height          =   135
  24.       Left            =   0
  25.       TabIndex        =   12
  26.       Top             =   1720
  27.       Width           =   2895
  28.    End
  29.    Begin VB.TextBox txtMyArray 
  30.       BeginProperty Font 
  31.          Name            =   "Arial"
  32.          Size            =   9.75
  33.          Charset         =   0
  34.          Weight          =   400
  35.          Underline       =   0   'False
  36.          Italic          =   0   'False
  37.          Strikethrough   =   0   'False
  38.       EndProperty
  39.       Height          =   300
  40.       Index           =   5
  41.       Left            =   1560
  42.       TabIndex        =   5
  43.       Text            =   "joseph_huntley@email.com"
  44.       Top             =   1430
  45.       Width           =   1335
  46.    End
  47.    Begin VB.TextBox txtMyArray 
  48.       BeginProperty Font 
  49.          Name            =   "Arial"
  50.          Size            =   9.75
  51.          Charset         =   0
  52.          Weight          =   400
  53.          Underline       =   0   'False
  54.          Italic          =   0   'False
  55.          Strikethrough   =   0   'False
  56.       EndProperty
  57.       Height          =   300
  58.       Index           =   4
  59.       Left            =   1560
  60.       TabIndex        =   4
  61.       Text            =   "Huntley"
  62.       Top             =   1140
  63.       Width           =   1335
  64.    End
  65.    Begin VB.TextBox txtMyArray 
  66.       BeginProperty Font 
  67.          Name            =   "Arial"
  68.          Size            =   9.75
  69.          Charset         =   0
  70.          Weight          =   400
  71.          Underline       =   0   'False
  72.          Italic          =   0   'False
  73.          Strikethrough   =   0   'False
  74.       EndProperty
  75.       Height          =   300
  76.       Index           =   3
  77.       Left            =   1560
  78.       TabIndex        =   3
  79.       Text            =   "Joseph"
  80.       Top             =   850
  81.       Width           =   1335
  82.    End
  83.    Begin VB.TextBox txtMyArray 
  84.       BeginProperty Font 
  85.          Name            =   "Arial"
  86.          Size            =   9.75
  87.          Charset         =   0
  88.          Weight          =   400
  89.          Underline       =   0   'False
  90.          Italic          =   0   'False
  91.          Strikethrough   =   0   'False
  92.       EndProperty
  93.       Height          =   300
  94.       Index           =   2
  95.       Left            =   1560
  96.       TabIndex        =   2
  97.       Text            =   "by"
  98.       Top             =   570
  99.       Width           =   1335
  100.    End
  101.    Begin VB.TextBox txtMyArray 
  102.       BeginProperty Font 
  103.          Name            =   "Arial"
  104.          Size            =   9.75
  105.          Charset         =   0
  106.          Weight          =   400
  107.          Underline       =   0   'False
  108.          Italic          =   0   'False
  109.          Strikethrough   =   0   'False
  110.       EndProperty
  111.       Height          =   300
  112.       Index           =   1
  113.       Left            =   1560
  114.       TabIndex        =   1
  115.       Text            =   "Array"
  116.       Top             =   290
  117.       Width           =   1335
  118.    End
  119.    Begin VB.TextBox txtMyArray 
  120.       BeginProperty Font 
  121.          Name            =   "Arial"
  122.          Size            =   9.75
  123.          Charset         =   0
  124.          Weight          =   400
  125.          Underline       =   0   'False
  126.          Italic          =   0   'False
  127.          Strikethrough   =   0   'False
  128.       EndProperty
  129.       Height          =   300
  130.       Index           =   0
  131.       Left            =   1560
  132.       TabIndex        =   0
  133.       Text            =   "Sort"
  134.       Top             =   0
  135.       Width           =   1335
  136.    End
  137.    Begin VB.Label lblMyArray 
  138.       Caption         =   "MyArray(5):"
  139.       BeginProperty Font 
  140.          Name            =   "Courier New"
  141.          Size            =   9.75
  142.          Charset         =   0
  143.          Weight          =   700
  144.          Underline       =   0   'False
  145.          Italic          =   0   'False
  146.          Strikethrough   =   0   'False
  147.       EndProperty
  148.       Height          =   255
  149.       Index           =   5
  150.       Left            =   120
  151.       TabIndex        =   11
  152.       Top             =   1430
  153.       Width           =   1335
  154.    End
  155.    Begin VB.Label lblMyArray 
  156.       Caption         =   "MyArray(4):"
  157.       BeginProperty Font 
  158.          Name            =   "Courier New"
  159.          Size            =   9.75
  160.          Charset         =   0
  161.          Weight          =   700
  162.          Underline       =   0   'False
  163.          Italic          =   0   'False
  164.          Strikethrough   =   0   'False
  165.       EndProperty
  166.       Height          =   255
  167.       Index           =   4
  168.       Left            =   120
  169.       TabIndex        =   10
  170.       Top             =   1140
  171.       Width           =   1335
  172.    End
  173.    Begin VB.Label lblMyArray 
  174.       Caption         =   "MyArray(3):"
  175.       BeginProperty Font 
  176.          Name            =   "Courier New"
  177.          Size            =   9.75
  178.          Charset         =   0
  179.          Weight          =   700
  180.          Underline       =   0   'False
  181.          Italic          =   0   'False
  182.          Strikethrough   =   0   'False
  183.       EndProperty
  184.       Height          =   255
  185.       Index           =   3
  186.       Left            =   120
  187.       TabIndex        =   9
  188.       Top             =   840
  189.       Width           =   1335
  190.    End
  191.    Begin VB.Label lblMyArray 
  192.       Caption         =   "MyArray(2):"
  193.       BeginProperty Font 
  194.          Name            =   "Courier New"
  195.          Size            =   9.75
  196.          Charset         =   0
  197.          Weight          =   700
  198.          Underline       =   0   'False
  199.          Italic          =   0   'False
  200.          Strikethrough   =   0   'False
  201.       EndProperty
  202.       Height          =   255
  203.       Index           =   2
  204.       Left            =   120
  205.       TabIndex        =   8
  206.       Top             =   570
  207.       Width           =   1335
  208.    End
  209.    Begin VB.Label lblMyArray 
  210.       Caption         =   "MyArray(1):"
  211.       BeginProperty Font 
  212.          Name            =   "Courier New"
  213.          Size            =   9.75
  214.          Charset         =   0
  215.          Weight          =   700
  216.          Underline       =   0   'False
  217.          Italic          =   0   'False
  218.          Strikethrough   =   0   'False
  219.       EndProperty
  220.       Height          =   255
  221.       Index           =   1
  222.       Left            =   120
  223.       TabIndex        =   7
  224.       Top             =   290
  225.       Width           =   1335
  226.    End
  227.    Begin VB.Label lblMyArray 
  228.       Caption         =   "MyArray(0):"
  229.       BeginProperty Font 
  230.          Name            =   "Courier New"
  231.          Size            =   9.75
  232.          Charset         =   0
  233.          Weight          =   700
  234.          Underline       =   0   'False
  235.          Italic          =   0   'False
  236.          Strikethrough   =   0   'False
  237.       EndProperty
  238.       Height          =   255
  239.       Index           =   0
  240.       Left            =   120
  241.       TabIndex        =   6
  242.       Top             =   0
  243.       Width           =   1455
  244.    End
  245. Attribute VB_Name = "frmMain"
  246. Attribute VB_GlobalNameSpace = False
  247. Attribute VB_Creatable = False
  248. Attribute VB_PredeclaredId = True
  249. Attribute VB_Exposed = False
  250. '**********************************************************
  251. '*             Sort Array by Joseph Huntley               *
  252. '*               joseph_huntley@email.com                 *
  253. '*                http://joseph.vr9.com                   *
  254. '*                                                        *
  255. '*  Made:  September 29, 1999                             *
  256. '*  Level: Intermediate                                   *
  257. '**********************************************************
  258. '*   The forms here are only used to demonstrate how to   *
  259. '* use the functions 'SortArray' and                      *
  260. '* FirstInAlphabeticalOrder'. You may copy the functions  *
  261. '* into your project for use. If you need any help,       *
  262. '* please e-mail me.                                      *
  263. '**********************************************************
  264. '* Notes: This could be used to sort a listbox instead of *
  265. '*        using the Sorted property.                      *
  266. '**********************************************************
  267. Sub SortArray(strArray() As String)
  268. '**********************************************************
  269. '*             Sort Array by Joseph Huntley               *
  270. '*               joseph_huntley@email.com                 *
  271. '*                http://joseph.vr9.com                   *
  272. '**********************************************************
  273. '*   You may use this code freely as long as credit is    *
  274. '* given to the author, and the header remains intact.    *
  275. '**********************************************************
  276. '--------------------- The Arguments ----------------------
  277. 'strArray    - The string array to sort.
  278. '----------------------------------------------------------
  279.   Dim intOut As Integer, intIn As Integer
  280.   Dim strTemp As String
  281.     'loop through array
  282.     For intOut% = LBound(strArray()) To UBound(strArray())
  283.         For intIn% = intOut% + 1 To UBound(strArray())
  284.             'check if the inner loop's current dimension is
  285.             'higher precendence, then the outer. If so, swap
  286.             'them.
  287.             If FirstInAlphabeticalOrder(strArray(intOut%), strArray(intIn%)) = 2 Then
  288.                strTemp$ = strArray(intIn%)
  289.                strArray(intIn%) = strArray(intOut%)
  290.                strArray(intOut%) = strTemp$
  291.             End If
  292.         Next intIn%
  293.     Next intOut%
  294. End Sub
  295. Function FirstInAlphabeticalOrder(strOne As String, strTwo As String) As Long
  296. '**********************************************************
  297. '*     First in Alphabetical Order by Joseph Huntley      *
  298. '*               joseph_huntley@email.com                 *
  299. '*                http://joseph.vr9.com                   *
  300. '**********************************************************
  301. '*   You may use this code freely as long as credit is    *
  302. '* given to the author, and the header remains intact.    *
  303. '**********************************************************
  304. '--------------------- The Arguments ----------------------
  305. 'strOne - The first string to compare.
  306. 'strTwo - The second string to compare.
  307. '----------------------------------------------------------
  308. 'Returns: 0 if strOne and strTwo are at the same level.
  309. '         1 if strOne is at a higher level.
  310. '         2 if strTwo is at a higher level.
  311. 'Description: Checks to see which of two strings is on a
  312. '             higher level. Alphabetically-wise.
  313.    Dim intChar As Integer, intLen As Integer
  314.    Dim strChar1 As String, strChar2 As String
  315.       'Check to see which string has more length
  316.       'assign intLen% the length of that string.
  317.       If Len(strOne$) > Len(strTwo$) Then
  318.          intLen% = Len(strOne$)
  319.       ElseIf Len(strTwo$) > Len(strOne$) Then
  320.          intLen% = Len(strTwo$)
  321.       Else
  322.          intLen% = Len(strOne$)
  323.       End If
  324.         
  325.       For intChar% = 1 To intLen%
  326.         strChar1$ = UCase$(Mid$(strOne$, intChar%, 1))
  327.         strChar2$ = UCase$(Mid$(strTwo$, intChar%, 1))
  328.            
  329.             'if no more character's are left on a string
  330.             'then that string automatically takes precedence.
  331.             'So exit the function.
  332.             If Len(strChar1$) = 0 Then
  333.                FirstInAlphabeticalOrder = 1
  334.                Exit Function
  335.             ElseIf Len(strChar2$) = 0 Then
  336.                FirstInAlphabeticalOrder = 2
  337.                Exit Function
  338.             End If
  339.             
  340.             'if character ascii value is between the ascii
  341.             'value of 'A' and 'Z', and the other character's
  342.             'ascii value is not. Precednce goes to the first
  343.             'string. If that and vice-versa is false. Check
  344.             'which ascii value is lower than the other ascii value.
  345.             'If one if it is lower that string takes precedence. If
  346.             'their equal, continue to the next character.
  347.             
  348.             If Asc(strChar1$) >= Asc("A") And Asc(strChar1$) <= Asc("Z") And Asc(strChar2$) <= Asc("A") And Asc(strChar2$) >= Asc("Z") Then
  349.                FirstInAlphabeticalOrder = 1
  350.                Exit Function
  351.             ElseIf Asc(strChar2$) >= Asc("A") And Asc(strChar2$) <= Asc("Z") And Asc(strChar1$) <= Asc("A") And Asc(strChar1$) >= Asc("Z") Then
  352.                FirstInAlphabeticalOrder = 2
  353.                Exit Function
  354.             ElseIf Asc(strChar1$) < Asc(strChar2$) Then
  355.                FirstInAlphabeticalOrder = 1
  356.                Exit Function
  357.             ElseIf Asc(strChar2$) < Asc(strChar1$) Then
  358.                FirstInAlphabeticalOrder = 2
  359.                Exit Function
  360.             End If
  361.                
  362.       Next intChar%
  363. End Function
  364. Private Sub cmdSort_Click()
  365.    Dim MyArray(0 To 5) As String 'declare array that we're gona sort
  366.    Dim intBuffer As Integer
  367.      For intBuffer% = 0 To 5
  368.         MyArray(intBuffer%) = txtMyArray(intBuffer%).Text
  369.      Next intBuffer%
  370.      
  371.    Call SortArray(MyArray())
  372.      For intBuffer% = 0 To 5
  373.         txtMyArray(intBuffer%).Text = MyArray(intBuffer%)
  374.      Next intBuffer%
  375.      
  376. End Sub
  377. Private Sub Form_Load()
  378. End Sub
  379.